package com.fishingwithme.infrastructure.dtos;

import com.fishingwithme.domain.spots.FishType;
import com.fishingwithme.domain.spots.HarvestType;
import com.fishingwithme.domain.spots.ScoreType;
import com.fishingwithme.infrastructure.utils.CommonUtils;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SpotHarvestDto {
    public static final String LIKE_TYPE = "H";
    private Long id;

    private Long spotId;

    private Long fisherId;

    private String harvest;
    private List<JsonNode> fishes;

    private String harvestType;
    private HarvestType harvestTypeVal;

    private Boolean isRec;

    private Integer score;
    private ScoreType scoreVal;

    private Date fishingAt;

    private String hisPictures;
    private List<String> jsonHisPictures;
    private String avatarUrl;
    private String nickName;
    private Integer lvl;
    private String lvlName;
    private Integer likeCount;
    private Boolean isLiked;


    public static SpotHarvestDto format(SpotHarvestDto dto) {
        dto.setFishes(CommonUtils.convert(dto.getHarvest(), FishType.class));
        dto.harvest = null;
        dto.setHarvestTypeVal(HarvestType.valueOf(dto.getHarvestType()));
        dto.setScoreVal(ScoreType.of(dto.getScore()));
        dto.setJsonHisPictures(CommonUtils.convert(dto.getHisPictures(), String.class));
        dto.hisPictures = null;
        return dto;
    }
}